<?php

include_once "header.php";

echo "<div class='container'>
<div class='row'>";
 
require_once "../dao/order_dao.php";
require_once "../dao/corder_dao.php";
require_once "../../config/paging.php";

$modul=$_GET['modul'];
$id=$_GET['id'];
$orderstat=$_GET['status'];
$breadcrump ="";
$store = $_SESSION['id_toko'];

switch($modul){
    
    default :
	
		$p = new Paging;
        $batas = 10;
        $posisi = $p->cari_posisi($batas);
				
		//$store = $_SESSION['id_toko'];
		//echo $store;
		
        echo "
            
            <table class='table table-bordered'>
                <tr><td colspan=6><a href='store_view.php?modul=tambah'><image src='../images/add.png'></a></td></tr>
                <th>ID</th><th>No PO</th><th>TANGGAL</th><th>PEMBELI</th><th>PEMBAYARAN</th><th>ALAMAT</th><th>PENGIRIMAN</th><th>TOTAL</th><th>STATUS</th><th>AKSI</th>             
			";
			
        $order = new Corder_Dao($class_db);
        
        $order->get_corder($store,$posisi,$batas);
		        
        $jmldata = count($order->order);
		//print_r($jmldata);
        
        $data = $order->order;
        
        if($data!=null) {
            
           foreach($data as $orders) {

			$order->db->hasil ="";
			$order->db->show_Data('customer','name',null,null,' customer_id='.$orders->customer);
			$hasil = $order->db->hasil;
			
			foreach($hasil as $customer){
                $customer = $customer['name'];
            }
            
			$totprice = number_format($orders->total,2,',','.');
			
			$q = "SELECT status FROM status_order WHERE id_status=".$orders->status;
			
			$status = $order->db->select_table($q);
			
			foreach($status as $data){
				$status = $data['status'];
			}
            
            $q = "SELECT kirim FROM kirim WHERE id_kirim=".$orders->shipping;
			
			$kirim = $order->db->select_table($q);
			
			foreach($kirim as $data){
				$kirim = $data['kirim'];
			}
            
            $q = "SELECT bayar FROM bayar WHERE id_bayar=".$orders->payment;
			
			$bayar = $order->db->select_table($q);
			
			foreach($bayar as $data){
				$bayar = $data['bayar'];
			}
			
            echo "
                <tr valign = top>
                    <td><a href='order_view.php?modul=detil&id=$orders->order_id'>$orders->order_id</a></td>
                    <td>$orders->nomor_po</td>
					<td>$orders->order_date</td>
                    <td>$customer</td>
					<td>$bayar</td>
					<td>$orders->ship_addr</td>
					<td>$kirim</td>
					<td>Rp. $totprice</td>
					<td>$status</td>
                    <td><a href='order_aksi.php?modul=update&id=$orders->order_id&orderstat=$orders->status'><image src='../images/edit.gif'></a> | 
                        <a href='order_aksi.php?modul=hapus&id=$orders->order_id'><image src='../images/delete.gif'></a>
					</td>
                </tr>
                ";        
            
            } 
        }else{
            echo "<tr><td colspan=5 align=center>DATA TIDAK DITEMUKAN</td></tr>";
        }
                        
        echo "            
			</table>
            ";
			
			$order->order = null;
			
			$order->get_corder();
			
			$jmldata = count($order->order);
			//print_r($jmldata);
        
			$jml_halaman = $p->jml_halaman($jmldata,$batas);
			//print_r($jml_halaman);
        
			$link_halaman = $p->navHalaman($modul,$_GET['halaman'],$jml_halaman);
        
			echo $link_halaman;
    break;    
    
    case "ubah":
    
        $toko = new Store_Dao($class_db);
        
        $toko->get_store($id);
        
        $store = $toko->store;
        
        foreach($store as $data) {
        
        echo "
            <form method='POST' action='store_aksi.php?modul=ubah' enctype='multipart/formdata'>
            <input type='hidden' name='id' value=$data->store_id>
            <table>
                <tr><td colspan=8 align='center'><h1>Ubah Data Toko</h1></td></tr>
					<tr><td>Nama Toko</td><td><input type='text' name='store_name' value='$data->store_name'></td></tr>
					<tr><td>Deskripsi</td><td><textarea name='description' row=4 col=20>$data->description</textarea></td></tr>
					<tr><td>Alamat :</td><td></td></tr>
                    <tr><td>Jalan</td><td><input type='text' name='street' value='$data->street'></td></tr>
                    <tr><td>Kecamatan</td><td><input type='text' name='kecamatan' value='$data->kecamatan'></td></tr>
                    <tr><td>Kota</td><td><input type='text' name='city' value=$data->city></td></tr>
                    <tr><td>Propinsi</td><td><input type='text' name='province' value=$data->province></td></tr>
                    <tr><td>Kode Pos</td><td><input type='text' name='zip_code' value=$data->zip_code></td></tr>
                    <tr><td>Logo</td><td><image src='$data->logo'></td></tr>
                    <tr><td></td><td><input type='file' name='logo' value='ganti logo'></td></tr>
                    <tr><td>Gambar Profil</td><td><image src='$data->image'></td></tr>
                    <tr><td></td><td><input type='file' name='image' value='ganti gb profil'></td></tr>
                    <tr><td colspan=2><input class='btn' type=submit value=Simpan><input class='btn' type=button value=Batal onclick=self.history.back()></td></tr>
				</table>
            </form>
            ";
            
            }
    
    break;
    
    case "detil":
    
       //$store = $_SESSION['id_toko'];
	   
	   echo "
            
            <table class='table table-bordered'>
                <tr><td colspan=6><input class='btn btn-primary' type=button value=Kembali onclick=self.history.back()></a></td></tr>
                <th>ID</th><th>PRODUK</th><th>HARGA</th><th>JUMLAH</th><th>TOTAL</th><th>AKSI</th>
                ";
        $orderdetail = new Order_Dao($class_db);
        
        $orderdetail->get_orderdetail($id,null,null,$store);
		        
        $jmldata = count($orderdetail->orderdetail);
		//print_r($jmldata);
        
        $data = $orderdetail->orderdetail;
		
		foreach($data as $orderdetails) {


			$orderdetail->db->hasil ="";
			$orderdetail->db->show_Data('product_detail','product_name',null,null,'store_id='.$store);
			//$hasil = orderdetail->db->select_table("select * from product_detail where store=$store");
			$hasil = $orderdetail->db->hasil;
			
			foreach($hasil as $product){
                $product = $product['product_name'];
            }
            
			$price = number_format($orderdetails->price,2,',','.');
			$totprice = number_format($orderdetails->total,2,',','.');
			
            echo "
                <tr valign = top>
                    <td>$orderdetails->order_id</td>
                    <td>$product</td>
					<!-- <td>$orderdetails->store</td> --!>
                    <td>Rp. $price</td>
					<td>$orderdetails->jumlah</td>
					<td>Rp. $totprice</td>
                    <td><a href='order_view.php?modul=ubah&id=$orderdetail->order_id'><image src='../images/edit.gif'></a> | 
                        <a href='order_aksi.php?modul=hapus&id=$orderdetail->order_id'><image src='../images/delete.gif'></a>
					</td>
                </tr>
                ";        
            
            } 
			
		
			
    break;
    
echo "</div></div>";
   
}